package com.changzhu.community.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.changzhu.community.entity.vo.ReguVo;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;

@Component
public class ExcelFileUtil {

    private static final Logger logger= LoggerFactory.getLogger(ExcelFileUtil.class);

    public int[] importFile(MultipartFile file){
        try{
            //上传起始时间
            Long start= System.currentTimeMillis();
            //创建输入流
            InputStream inputStream=file.getInputStream();
            //使用workbook
            Workbook workbook = new XSSFWorkbook(inputStream);
            //获取workbook中的第一个sheet
            Sheet sheet=workbook.getSheetAt(0);
            //获取总行数
            int rowNum=sheet.getPhysicalNumberOfRows();
            //获取总列数
            int columnNum=sheet.getRow(0).getPhysicalNumberOfCells();
            //循环遍历
            for(int i=1;i<rowNum;i++){
                //获取每一行
                Row row=sheet.getRow(i);
                //获取每一列的内容
                for(int j=0;j<columnNum;j++){
                    if(row.getCell(j)!=null){
                        logger.debug(row.getCell(j).getStringCellValue());
                    }
                }
            }
            return new int[]{0,0};
        }catch (Exception e){
            logger.error("导入数据异常",e);
            return new int[]{0,0};
        }
    }


//    public List<ReguVo> getTree(){
//        QueryWrapper<TLawRegulationInfo> queryWrapper=new QueryWrapper<>();
//        queryWrapper.groupBy("charpter_title");
//
//        return null;
//    }

}
